﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TERP.WaterClient.Common;
using System.Data;
using CommonUtils;

namespace TERP.WaterClient.DbServices
{
    public class ReceiptService : BaseService
    {

		public ReceiptService()
            : base()
        {
        }

		public DataSet Its_Receipt_Get(
                        string strReceiptD
						, string strDateReceiptFrom
						, string strDateReceiptTo
						, string strCusID
            )
        {
			string strReceiptDConditionList = "";
			string strDateReceiptConditionList="";
			string strCusIDConditionList="";

			if (!StringUtils.IsEmpty(strCusID))
			{
			    strCusIDConditionList = "=  " + strCusID;
			}
			if (!StringUtils.IsEmpty(strReceiptD))
			{
				strReceiptDConditionList = "= " + strReceiptD;
			}			

			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
			DataSet mdsFinal = new DataSet();
			mdsFinal  = _dbService.Its_Receipt_Get(
					  _strGwUserCode,
					  _strGwPassword,
					  strTId,
					  _strSessionId,
					  strReceiptDConditionList
					  , strDateReceiptConditionList
					  , strCusIDConditionList
			      );
			    mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
			    if (CMyDataSet.HasError(mdsFinal))
			    {
			        throw GenServiceException(mdsFinal);
			    }
			return mdsFinal;
			}
			catch (Exception ex)
			{
			    throw ex;
			}
        }

		public DataSet Its_Receipt_Create(
						 string strReceiptCode
			 , string strDateReceipt
			 , string strNote
			 , string strCusID
			 , string strAmount
			 , string strReceiptType
			)
		{
					

			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Receipt_Create(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId
						 ,  strReceiptCode
						 ,  strDateReceipt
						 ,  strNote
						 ,  strCusID
						 ,  strAmount
						 ,  strReceiptType
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public DataSet Its_Receipt_Update(
						 string strReceiptID
						 , string strReceiptCode
						 , string strDateReceipt
						 , string strNote
						 , string strCusID
						 , string strAmount
						 , string strReceiptType
			)
		{


			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Receipt_Update(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId
						  ,  strReceiptID
						 ,  strReceiptCode
						 ,  strDateReceipt
						 ,  strNote
						 ,  strCusID
						 ,  strAmount
						 ,  strReceiptType
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}


		public DataSet Its_Receipt_Delete(
						string strReceiptID
			)
		{


			string strTId = SystemGlobal.Instance.GetNextTid();
			//
			try
			{
				DataSet mdsFinal = new DataSet();
				mdsFinal = _dbService.Its_Receipt_Delete(
						  _strGwUserCode,
						  _strGwPassword,
						  strTId,
						  _strSessionId,
						  strReceiptID
					  );
				mdsFinal = TERP.Utils.CUtils.MyDSDecode(mdsFinal);
				if (CMyDataSet.HasError(mdsFinal))
				{
					throw GenServiceException(mdsFinal);
				}
				return mdsFinal;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
    }

}
